
import { MousePosition, createStringXY } from "../ol"

/**
 * openlayer 
 */
export default class Event {
    /**
     * map 对象
     */
    map: any;

    constructor(map: any) {
        this.map = map;
    }
    /**
     * 监听鼠标移动---获取当前鼠标所在位置的坐标
     */
    MousePosition = (sub: any, demoInputw: string) => {
        if (sub && sub.pageX) {

        }
        let target: any = document.getElementById(demoInputw);
        let pixel = [sub.pageX, sub.pageY];
        let CFP = this.map.getCoordinateFromPixel(pixel);
        if (CFP && CFP[0] && CFP[1]) {
            target.innerHTML = `经度:${CFP[0].toFixed(12)},纬度:${CFP[1].toFixed(12)}`;
        }

    }
    /**
     * 点击事件
     */
    singleclick = (event: any) => {
        this.map.on('singleclick', event)
    }
    /**
     * 点击事件
     */
    setdblclick = (event: any) => {
        this.map.on('dblclick', event)
    }
    /**
     * 当鼠标缩放结束后回调事件
     * @param event 返回事件
     */
    Moveend = (event: (e: any) => void) => {
        this.map.on("moveend", (e: any) => {


            var zoom = this.map.getView().getZoom();  //获取当前地图的缩放级别
            event(zoom.toFixed(1));
        });

    }
}